package com.ruoyi.web.controller.system;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.service.IAppGroupInfoService;
import com.ruoyi.system.service.IAppUserCollectService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BaseReportDay;
import com.ruoyi.system.service.IBaseReportDayService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报每日在线人数和每日注册用户Controller
 *
 * @author ruoyi
 * @date 2023-03-13
 */
@RestController
@RequestMapping("/system/day")
public class BaseReportDayController extends BaseController {
    @Autowired
    private IBaseReportDayService baseReportDayService;
    @Autowired
    private IAppUserCollectService appUserCollectService;
    @Autowired
    private IAppGroupInfoService appGroupInfoService;

    /**
     * 查询报每日在线人数和每日注册用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:day:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseReportDay baseReportDay) {
        startPage();
        List<BaseReportDay> list = baseReportDayService.selectBaseReportDayList(baseReportDay);
        return getDataTable(list);
    }

    /**
     * 导出报每日在线人数和每日注册用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:day:export')")
    @Log(title = "报每日在线人数和每日注册用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseReportDay baseReportDay) {
        List<BaseReportDay> list = baseReportDayService.selectBaseReportDayList(baseReportDay);
        ExcelUtil<BaseReportDay> util = new ExcelUtil<BaseReportDay>(BaseReportDay.class);
        util.exportExcel(response, list, "报每日在线人数和每日注册用户数据");
    }

    /**
     * 获取报每日在线人数和每日注册用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:day:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(baseReportDayService.selectBaseReportDayById(id));
    }

    /**
     * 新增报每日在线人数和每日注册用户
     */
    @PreAuthorize("@ss.hasPermi('system:day:add')")
    @Log(title = "报每日在线人数和每日注册用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseReportDay baseReportDay) {
        return toAjax(baseReportDayService.insertBaseReportDay(baseReportDay));
    }

    /**
     * 修改报每日在线人数和每日注册用户
     */
    @PreAuthorize("@ss.hasPermi('system:day:edit')")
    @Log(title = "报每日在线人数和每日注册用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseReportDay baseReportDay) {
        return toAjax(baseReportDayService.updateBaseReportDay(baseReportDay));
    }

    /**
     * 删除报每日在线人数和每日注册用户
     */
    @PreAuthorize("@ss.hasPermi('system:day:remove')")
    @Log(title = "报每日在线人数和每日注册用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseReportDayService.deleteBaseReportDayByIds(ids));
    }

    /**
     * 每日在线人数
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:day:listOnlineNumber')")
    @GetMapping("/listOnlineNumber")
    public TableDataInfo listOnlineNumber(BaseReportDay baseReportDay) {
        List<BaseReportDay> numberPeopleCountedVos = baseReportDayService.dailyOnlineNumber(baseReportDay);
        return getDataTable(numberPeopleCountedVos);
    }

    /**
     * 每日注册人数
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:day:listRegistrations')")
    @GetMapping("/listRegistrations")
    public TableDataInfo listRegistrations(BaseReportDay baseReportDay) {
        List<BaseReportDay> numberPeopleCountedVos = baseReportDayService.dailyRegistrations(baseReportDay);
        return getDataTable(numberPeopleCountedVos);
    }


    /**
     * 首页折线图数据
     */
    @GetMapping("/chart/{types}")
    public TableDataInfo indexChartData(@PathVariable Long[] types) {
        List<BaseReportDay> list = baseReportDayService.indexChartData(types);
        return getDataTable(list);
    }


    @GetMapping(value = "/selectNum")
    public AjaxResult selectNum() {
        Map<String, Integer> map= new HashMap<>();

        //今日注册人数
        int regNum = appUserCollectService.selectRegistTodayNum();
        map.put("registTodayNum",regNum);

        //用户人数
        int appUserNum = appUserCollectService.selectUserNum();
        map.put("appUserNum",appUserNum);

        //群组数量
        int InfoNum = appGroupInfoService.selectInfoNum();
        map.put("InfoNum",InfoNum);
        return success(map);
    }


}
